<?php /* Smarty version Smarty-3.1.6, created on 2018-08-05 20:03:48
         compiled from "/Applications/MAMP/htdocs/svn/myshop/Home/View/Draw/inroom.html" */ ?>
<?php /*%%SmartyHeaderCode:18835593975b5d601e800d56-44182279%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    '389d8479d2a0ed46aaf26ce4707ba1581bdb77da' => 
    array (
      0 => '/Applications/MAMP/htdocs/svn/myshop/Home/View/Draw/inroom.html',
      1 => 1533470601,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '18835593975b5d601e800d56-44182279',
  'function' => 
  array (
  ),
  'version' => 'Smarty-3.1.6',
  'unifunc' => 'content_5b5d601e8657b',
  'variables' => 
  array (
    'users' => 0,
    'v' => 0,
    'has_ready' => 0,
    'roomuid' => 0,
  ),
  'has_nocache_code' => false,
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_5b5d601e8657b')) {function content_5b5d601e8657b($_smarty_tpl) {?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>游戏房间</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="<?php echo @PUBLIC_PATH;?>
css/amazeui.min.css">
    <script type="text/javascript" src="<?php echo @PUBLIC_PATH;?>
js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="<?php echo @PUBLIC_PATH;?>
js/amazeui.min.js"></script>
    <script  type="text/javascript" src="<?php echo @PUBLIC_PATH;?>
js/myself/websocket.js"></script>
    <style>
        .am-badge{
            float: right;
            line-height:normal;
        }
        .am-img-thumbnail{
            width:40px;
        }
    </style>
</head>
<body>
    <ul class="am-list am-list-border">
        <?php  $_smarty_tpl->tpl_vars['v'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['v']->_loop = false;
 $_smarty_tpl->tpl_vars['k'] = new Smarty_Variable;
 $_from = $_smarty_tpl->tpl_vars['users']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['v']->key => $_smarty_tpl->tpl_vars['v']->value){
$_smarty_tpl->tpl_vars['v']->_loop = true;
 $_smarty_tpl->tpl_vars['k']->value = $_smarty_tpl->tpl_vars['v']->key;
?>
        <li>
            <img src="<?php echo $_smarty_tpl->tpl_vars['v']->value['main_img'];?>
" alt="..." class="am-img-thumbnail am-radius">
            <span><?php echo $_smarty_tpl->tpl_vars['v']->value['name'];?>
</span>

            <?php if ($_smarty_tpl->tpl_vars['v']->value['uid']==$_smarty_tpl->tpl_vars['users']->value['host']['uid']){?>
                <span class="am-badge am-badge-success start" data-uid="<?php echo $_smarty_tpl->tpl_vars['v']->value['uid'];?>
">开始游戏</span>
                <span class="am-badge am-badge-warning">房主</span>
            <?php }else{ ?>
                <?php if (in_array($_smarty_tpl->tpl_vars['v']->value['uid'],$_smarty_tpl->tpl_vars['has_ready']->value)){?>
                    <span id="p<?php echo $_smarty_tpl->tpl_vars['v']->value['uid'];?>
" class="am-badge am-badge-success" data-uid="<?php echo $_smarty_tpl->tpl_vars['v']->value['uid'];?>
">已准备</span>
                <?php }else{ ?>
                    <span id="p<?php echo $_smarty_tpl->tpl_vars['v']->value['uid'];?>
" class="am-badge am-badge-success ready" data-uid="<?php echo $_smarty_tpl->tpl_vars['v']->value['uid'];?>
">准备</span>
                <?php }?>
            <?php }?>
        </li>
        <?php } ?>
    </ul>
    <div style="text-align: center;" >
        <a class="am-btn am-btn-success flush" >刷新</a>
    </div>
</body>
<script>
    var socket = new WebSocket('ws://192.168.1.7:8888/test.php');
    socket.onopen = function(event) {
        console.log('连接成功');
        // console.log(socket.readyState)
        var content=JSON.stringify({ "type":"in","roomuid":"<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
"})
        socket.send(content);
    };

    socket.onmessage = function(event) {
        var msg = event.data;
        // console.log(msg);return;
        msg=JSON.parse(msg);
        msg=JSON.parse(msg);
        // msg=JSON.parse(msg)
        console.log(msg);
        // return;
        // if(msg.type=="ready"&&msg.roomuid=="<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
"){
        //     window.location.reload()
        // }else if(msg.type=="start"&&msg.roomuid=="<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
"){
        //     window.location.href="<?php echo @__MODULE__;?>
/Draw/room/room_uid/<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
"
        // }else{
        //     alert("socket错误")
        // }
        if(msg.roomuid=="<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
"){ //表示是该房间的消息
            switch (msg.type) {
                case "ready":
                    window.location.reload()
                    break;
                case "start":
                    window.location.href="<?php echo @__MODULE__;?>
/Draw/room/room_uid/<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
"
                    break;
                case "in":
                    window.location.reload()
                    break;
                default :
                    alert("socket错误")
            }
        }

    };


        $(".ready").click(function(){
        var thisp=$(this)
        var uid="<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
";
        var data={
            "room_uid":uid,
            "user_uid":thisp.data("uid"),
        }
        // console.log(data); return
        $.post("<?php echo @__MODULE__;?>
/Ajax/set_ready",data,function (ret) {
            // console.log(ret)
            if(ret.error){
                console.log(ret.error)
                content=JSON.stringify({ "type":"ready","roomuid":uid})
                socket.send(content);
                thisp.text('已准备')
                // thisp.removeClass("ready")
            }else{
                // console.log(thisli.data("href"))
                //window.location.href=thisli.data("href")
            }
            // console.log(ret)
        })

        // console.log("<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
")
    })
    $(".start").click(function(){
        var uid="<?php echo @$_smarty_tpl->tpl_vars['roomuid']->value;?>
";
        var data={
            "host_uid":$(this).data("uid"),
            "room_uid":uid,
        }
        $.post("<?php echo @__MODULE__;?>
/Ajax/start",data,function (ret) {
            // console.log(ret)
            if(ret.error){
                // console.log(ret)
                content=JSON.stringify({ "type":"start","roomuid":uid})
                socket.send(content);
                window.location.href="<?php echo @__MODULE__;?>
/Draw/room/room_uid/"+uid
            }else{
                alert(ret.course)
                //window.location.href=thisli.data("href")
            }
            // console.log(ret)
        })

    })
</script>
</html><?php }} ?>